package leetcode_201_300;

import java.util.*;

public class LeeCode_229 {
    public static void main(String[] args) {

    }
    private static List<Integer> majorityElement(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        List<Integer> ans = new ArrayList<>();
        int count = nums.length / 3;
        for (int num : nums) {
            if (map.containsKey(num)){
                map.put(num, map.get(num) + 1);
                continue;
            }
            map.put(num, 1);
        }
        Set<Integer> keys = map.keySet();
        for (Integer key : keys) {
            if (map.get(key) > count){
                ans.add(key);
            }
        }
        return ans;
    }
}
